package com.fashiontextile.user.controller;

import com.fashiontextile.common.entity.R;
import com.fashiontextile.user.entity.Role;
import com.fashiontextile.user.service.RoleService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author brooke_zb
 */
@RestController
@RequestMapping("/role")
@AllArgsConstructor
public class RoleController {
    RoleService roleService;

    @GetMapping("/rid/{rid:\\d+}")
    public R<Role> getRoleByRid(@PathVariable Integer rid) {
        Role role = roleService.selectByRid(rid);
        if (role == null) {
            return R.fail("角色不存在");
        } else {
            return R.success(role);
        }
    }

    @GetMapping("/name/{name}")
    public R<Role> getRoleByName(@PathVariable String name) {
        Role role = roleService.selectByName(name);
        if (role == null) {
            return R.fail("角色不存在");
        } else {
            return R.success(role);
        }
    }
}
